﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Xyz.Web.Reservation.AircraftSeatService;
using Xyz.Web.Reservation.BookingService;

namespace Xyz.Web.Reservation.Repositories
{
    public class SeatRepository :BaseRepository
    {

        public List<AircraftSeatDTO> GetAllAircraftSeatByAircraftId(int aircraftId)
        {
           

            return AircraftSeatServiceClient.GetAllAircraftSeats(aircraftId).ToList();
        }

        public AircraftSeatDTO getAircraftSeatByAircraftIdSeatCode(int aircraftId, string seatCode)
        {

            return AircraftSeatServiceClient.getAircraftSeatByAircraftIdSeatCode(aircraftId, seatCode);
        }

        public AircraftDTO getAircraftByFlightId(int flightId)
        {
           
             return BookingServiceClient.getAircraftByFlightId(flightId);
          
        }

        public List<AircraftSeatDTO> GetAllAircraftSeatByFlightId(int flightId)
        {
            AircraftDTO aircraftDto = getAircraftByFlightId(flightId);
            return GetAllAircraftSeatByAircraftId(aircraftDto.AircraftId);
        }


        public List<AircraftSeatDTO> GetAircraftSeatByFlightIdSeatTypeCode(int flightId, String seatTypeCode)
        {
            AircraftDTO aircraftDto = getAircraftByFlightId(flightId);
            return GetAircraftSeatByAircraftIdSeatTypeCode(aircraftDto.AircraftId, seatTypeCode);
        }

        public List<AircraftSeatDTO> GetAircraftSeatByAircraftIdSeatTypeCode(int aircraftId, String seatTypeCode)
        {
           

            return AircraftSeatServiceClient.GetAircraftSeatByAircraftIdSeatTypeCode(aircraftId, seatTypeCode).ToList();
        }

        public List<AircraftSeatDTO> GetAvaliableAircraftSeatByFlightIdSeatTypeCode(int flightId, String seatTypeCode)
        {
            List<AircraftSeatDTO> aircraftSeats = GetAircraftSeatByFlightIdSeatTypeCode(flightId, seatTypeCode);
           
            List<AircraftSeatDTO> avaliableAircraftSeats = new List<AircraftSeatDTO>();

            foreach (AircraftSeatDTO aircraftSeatDto in aircraftSeats)
            {

                Boolean booked = BookingServiceClient.IsBookedSeat(flightId, aircraftSeatDto.AircraftSeatId);
                if (!booked)
                {
                    avaliableAircraftSeats.Add(aircraftSeatDto);
                }
            }
            return avaliableAircraftSeats;
        }

        public decimal GetFlightPriceByFlightIdSeatTypeCode(int flightId, string seatTypeCode)
        {
            
            return FlightPriceServiceClient.GetFlightPriceByFlightIdSeatTypeCode(flightId, seatTypeCode);
        }

        public FlightSeatDTO SaveBlockFlightSeat(FlightSeatDTO flightSeatDto)
        {

            return BookingServiceClient.SaveBlockFlightSeat(flightSeatDto);
        }
        public void CancelBlockFlightSeat(int flightSeatId)
        {

            BookingServiceClient.CancelBlockFlightSeat(flightSeatId);
        }
        

    }
}